#include "Mesh.hpp"
#include <iostream>

const int Mesh::OBJ_MODE = 0;
const int Mesh::MANUAL_MODE = 1;

bool Mesh::LoadObj(const char* filename)
{
	ReadFile(filename, vList, tList);

	glGenBuffers(1, &vertexBufferObject);
	glGenBuffers(1, &normalsBufferObject);
	glGenBuffers(1, &indexBufferObject);


	glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vList.GetNumberOfVertices() * 3, vList.ToVertexFloatArray(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	//std::cin.get();
	glBindBuffer(GL_ARRAY_BUFFER, normalsBufferObject);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vList.GetNumberOfVertices() * 3, vList.ToNormalFloatArray(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * tList.GetNumberOfTriangles() * 3, tList.ToIndexArray(), GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);



	return true;
}

